package com.huangtang.pc.serializer;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;

/**
 * @author sunjf
 * @date 2024/03/01
 */
public class LocalDateTimeToTimeStampSerializer extends JsonSerializer<TemporalAccessor> {
    @Override
    public void serialize(TemporalAccessor temporalAccessor, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeNumber(LocalDateTimeUtil.toEpochMilli(temporalAccessor));
    }
}
